package com.joseph.websocket.client;

import com.google.common.util.concurrent.*;

import javax.annotation.Nullable;
import java.util.concurrent.*;

public class DCLInstance1 {

    private static volatile DCLInstance1 INSTANCE = null;

    public static void main(String[] args) throws Exception {
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        Future<Object> submit = executorService.submit(new Callable<Object>() {
            @Override
            public Object call() throws Exception {
                System.out.println("call in");
                TimeUnit.SECONDS.sleep(5);
                System.out.println("call out");
                return 10;
            }
        });

        executorService.submit(new Runnable() {
            @Override
            public void run() {
                while (true) {
                    if (submit.isDone()) {
                        try {
                            System.out.println("result:" + submit.get());
                            break;
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } catch (ExecutionException e) {
                            e.printStackTrace();
                        }
                    } else {
                        Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
                    }
                }
            }
        });

        System.out.println("end");
    }
}
